package icu.ac.kr.simpleRssReader.network;

 
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import android.content.ContentResolver;
import android.util.Log;

public class Communication {

	final String TAG = "Communication";
	ContentResolver cp;
	
	public Communication(ContentResolver contentResolver) {
		// TODO Auto-generated constructor stub
		cp = contentResolver;
	}

	public void downloadXML(String addr) throws Exception {
		// TODO Auto-generated method stub
		
			Log.d(TAG, "WEB : " + addr);
			URL url = new URL(addr);
			HttpURLConnection con = (HttpURLConnection) url.openConnection();
			
			SAXParserFactory factory = SAXParserFactory.newInstance();
			SAXParser parser = factory.newSAXParser();
			XMLReader reader = parser.getXMLReader();
			reader.setContentHandler(new icu.ac.kr.simpleRssReader.parser.WebParser(cp, addr));
			reader.parse(new InputSource(con.getInputStream()));
			
			Log.d(TAG, "Parsing success");
		
	}

}
